package cn.jolyoulu.modules.druidmodule.utils.db.mysql;



import cn.jolyoulu.common.druid.utils.db.mysql.MysqlDBUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import cn.jolyoulu.common.druid.entity.TableColumnInfo;
import cn.jolyoulu.common.druid.entity.TableInfo;

import java.util.List;
import java.util.Objects;

/**
 * @Author LuZhouJin
 * @Date 2023/7/25
 */
class MysqlDBUtilsTest {

    private static MysqlDBUtils utils = null;

    @Before
    public void testBefore() {
        System.out.println("建立连接");
        utils = MysqlDBUtils.build("localhost", "3306", "root", "123456");
        assert Objects.nonNull(utils) : "建立连接失败";
    }

    @After
    void close() {
        utils.close();
        System.out.println("关闭连接");
    }

    @Test
    public void check() {
        boolean check = utils.check();
        assert check : "utils.check() 返回失败";
        System.out.println("测试数据库连接正常 => " + check);
    }

    @Test
    void selectDatabases() {
        List<String> list = utils.selectDatabases();
        assert !list.isEmpty() : "utils.selectDatabases() 返回空列表";
        System.out.println("数据库表信息 => " + list);
    }

    @Test
    void selectTables() {
        List<TableInfo> list = utils.selectTables("information_schema");
        assert !list.isEmpty() : "utils.selectTables() 返回空列表";
        System.out.println("information_schema库中的表信息 => " + list);
    }

    @Test
    void selectTableColumns() {
        List<TableColumnInfo> list = utils.selectTableColumns("information_schema", "USER_PRIVILEGES");
        assert !list.isEmpty() : "utils.selectTableColumns() 返回空列表";
        System.out.println("information_schema库USER_PRIVILEGES表信息 => " + list);
    }
}